#include <stdint.h>
#include <jni.h>
#include <android/native_window.h>
#include <android/native_window_jni.h>

#include "jniwrapper.h"

#include <strings.h>
#include <android/log.h>

#include "Engine/Program.h"
#include "Graphics/OpenGL/GLRenderEngine.h"

static ANativeWindow *window = 0;
tyro::Engine::Program program;

JNIEXPORT void JNICALL Java_tyro_engine_android_MainActivity_nativeOnCreate(JNIEnv* jenv, jobject obj)
{
	__android_log_print(ANDROID_LOG_INFO, "LOG_TAG", "On Create");

	program.Run();

	return;
}

JNIEXPORT void JNICALL Java_tyro_engine_android_MainActivity_nativeOnResume(JNIEnv* jenv, jobject obj)
{
	__android_log_print(ANDROID_LOG_INFO, "LOG_TAG", "On Resume");
	//renderer->start();
	return;
}

JNIEXPORT void JNICALL Java_tyro_engine_android_MainActivity_nativeOnPause(JNIEnv* jenv, jobject obj)
{
	__android_log_print(ANDROID_LOG_INFO, "LOG_TAG", "On Pause");
	//renderer->stop();
	return;
}

JNIEXPORT void JNICALL Java_tyro_engine_android_MainActivity_nativeOnStop(JNIEnv* jenv, jobject obj)
{
	__android_log_print(ANDROID_LOG_INFO, "LOG_TAG", "On Stop");
	//delete renderer;
	//renderer = 0;
	return;
}

JNIEXPORT void JNICALL Java_tyro_engine_android_MainActivity_nativeSetSurface(JNIEnv* jenv, jobject obj, jobject surface)
{
	if (surface != 0) {
	        window = ANativeWindow_fromSurface(jenv, surface);
	        __android_log_print(ANDROID_LOG_INFO, "LOG_TAG", "Got window %p", window );
	        //renderer->setWindow(window);
	} else {
	    	__android_log_print(ANDROID_LOG_INFO, "LOG_TAG", "Releasing window" );
	    	ANativeWindow_release(window);
	}

	return;
}
